<?php
// +----------------------------------------------------------------------
// | Jqcms [ Avenue to Jane ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017 http://jqcms.net All rights reserved.
// +----------------------------------------------------------------------
// | Author: hyacinth <845077398@qq.com>
// +----------------------------------------------------------------------
namespace Admin\Model;
use Think\Model;

class AdModel extends Model{
    
    protected $_validate = array(
      
        array('name','require','名称不能为空!'),
        array('url','require','链接不能为空!'),
        array('name','','广告标识已存在！',0,'unique',1),
        
    );
    
    protected $_auto = array(
        
        array('pic','upload',3,'callback'),
        
    );
    
    public function upload(){
    
        if($_FILES['pic']['name']){
             
            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize   =     3145728 ;// 设置附件上传大小
            $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
            $upload->rootPath  =     './Uploads/'; // 设置附件上传根目录
            $upload->savePath  =     'img/'.date('Ym',time()).'/'; // 设置附件上传（子）目录
            $upload->subName = array('date','d');//子目录创建方式
            $upload->saveName  = date('Ymd',time()).'_'.mt_rand();
            // 上传文件
            $info   =   $upload->uploadOne($_FILES['pic']);
            if(!$info) {// 上传错误提示错误信息
                //$this->error($upload->getError());
            }else{// 上传成功
                return $info['savepath'].$info['savename'];
                //$this->success('上传成功！');
            }
             
        }else {
            return $_POST['_pic'];
        }
    }
    
    
    
    
}